package cn.south.campus.admin.sys.controller;

import cn.south.campus.admin.sys.model.req.LoginReq;
import cn.south.campus.admin.sys.model.vo.LoginVO;
import cn.south.campus.admin.sys.service.LoginService;
import cn.south.campus.common.model.bo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2023/3/14 9:28
 */
@RestController
@RequestMapping("/admin")
public class LoginController {

    @Resource
    private LoginService loginService;

    @PostMapping("login")
    public Result<String> login(@RequestBody @Valid LoginReq req) {
        return Result.success(loginService.login(req));
    }

    @PostMapping("logout")
    public Result<String> logout() {
        loginService.logout();
        return Result.success("退出成功");
    }

    @GetMapping("userInfo")
    public Result<LoginVO> userInfo() {
        return Result.success(loginService.userInfo());
    }

    @PostMapping("modifyInfo")
    public Result<String> modifyInfo(@RequestBody @Valid LoginVO vo) {
        loginService.modifyInfo(vo);
        return Result.success("修改成功");
    }

}
